package com.kfm.jdbc.day0404.thread;

public class StopDemo {


    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                int count = 1;
                while (!Thread.currentThread().isInterrupted()){
                    System.out.println("线程的任务");
                    // 休眠
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    count ++;
                    if (count > 5) {
                        // 线程中断
                        Thread.currentThread().interrupt();
                    }
                }
            }
        }, "线程A");

        t1.start();

        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        // 线程中断
//        t1.stop();

    }
}
